package com.darren.archive.entity;

import com.darren.framework.entity.BaseEntity;
import com.darren.framework.utils.Constant;
import org.hibernate.annotations.ResultCheckStyle;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import java.io.Serializable;
import java.util.List;

@Entity
@Table(name = Constant.TABLE_NAME_PREV + "provinces")
@SQLDelete(sql = "update " + Constant.TABLE_NAME_PREV + "provinces set is_delete = true where id=?", check = ResultCheckStyle.COUNT)
@Where(clause = "is_delete  = false")
public class Province extends BaseEntity implements Serializable {

    private static final long serialVersionUID = 2861478466077717714L;

    /**
     * 省份编号
     */
    @Column(name = "province_code", columnDefinition = "varchar(20) comment '省份编号'")
    private String provinceCode;

    /**
     * 省份名字
     */
    @Column(name = "province_name", columnDefinition = "varchar(50) comment '省份名字'")
    private String provinceName;

    @OneToMany(targetEntity = City.class, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JoinColumn(name = "province_code", referencedColumnName = "province_code")
    private List<City> cities;


    public String getProvinceCode() {
        return provinceCode;
    }

    public void setProvinceCode(String provinceCode) {
        this.provinceCode = provinceCode;
    }

    public String getProvinceName() {
        return provinceName;
    }

    public void setProvinceName(String provinceName) {
        this.provinceName = provinceName;
    }

    public List<City> getCities() {
        return cities;
    }

    public void setCities(List<City> cities) {
        this.cities = cities;
    }

}
